package com.kkd.kkdapp.activity;

import java.util.ArrayList;
import java.util.List;

import android.animation.Animator;
import android.animation.Animator.AnimatorListener;
import android.animation.ObjectAnimator;
import android.animation.PropertyValuesHolder;
import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.FragmentTransaction;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.FrameLayout;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.kkd.kkdapp.R;
import com.kkd.kkdapp.base.BaseActivity;
import com.kkd.kkdapp.fragment.DealDetailFragment;
import com.kkd.kkdapp.fragment.DealDetailPinnerFragment;
import com.kkd.kkdapp.utils.SystemUtils;

/**
 * 交易明细
 * 
 * @author mty
 */
public class DealDetailsActivity extends BaseActivity implements
		OnClickListener {

	private Context mContext = this;

	private TextView classify_tv;
	private PopupWindow mPopupWindow;
	private int level = 1;
	private RelativeLayout deal_top_img; // 返回
	private RelativeLayout deal_top; // 头部
	private List<String> list;
	private boolean allFlag = false;
	private boolean underwayFlag = true;
	private FrameLayout frame_all;
	private FrameLayout frame_lixihuankuan;
	private FrameLayout frame_benjinhuankuan_sort;
	private FrameLayout frame_cunqianguan;
	private FrameLayout frame_recharge;
	private FrameLayout frame_coupon_return;
	private FrameLayout frame_jianglixianjin;
	private FrameLayout frame_Invitation_to_return;
	private FrameLayout frame_withdraw;
	private int numFlag = 0;
	private View view_bottom;
	private int integerFlag = 0; // 偶数打开分类窗口，基数关闭分类窗口
	private RelativeLayout myticket;
	private RelativeLayout rel_selectSort;
	private TextView tv_toAll_sort;
	private TextView tv_toRecharge_sort;
	private TextView tv_toLixihuankuan_sort;
	private TextView tv_toBenjinhuankuan_sort;
	private TextView tv_toYaoqinghaoyou_sort;
	private TextView tv_toCunqianguan_sort;
	private TextView tv_toYouhuiquan_sort;
	private TextView tv_toJianglixianjin_sort;
	private TextView tv_toWithdraw_sort;
	private TextView tv_toWithdrawExtra_sort;
	private TextView tv_toTenderkoukuan_sort;
	private TextView tv_toGoumaizhaiquan_sort;
	private TextView tv_toHistory_sort;
	private TextView tv_toLiubiaojiedong_sort;
	private TextView tv_toJiekuanxiangguan_sort;
	private TextView tv_toFuwufei_sort;
	private TextView deal_top_tv;

	private FrameLayout frame_withdrawExtra;

	private FrameLayout frame_tenderkoukuan;

	private FrameLayout frame_history;

	private FrameLayout frame_liubiaojiedong;

	private FrameLayout frame_jiekuanxiangguan;

	private FrameLayout frame_goumaizhaiquan;

	private RelativeLayout rel_toAll_sort;

	private RelativeLayout rel_toRecharge_sort;

	private RelativeLayout rel_toLixihuankuan_sort;

	private RelativeLayout rel_toBenjinhuankuan_sort;

	private RelativeLayout rel_toYaoqinghaoyou_sort;

	private RelativeLayout rel_toCunqianguan_sort;

	private RelativeLayout rel_toYouhuiquan_sort;

	private RelativeLayout rel_toJianglixianjin_sort;

	private RelativeLayout rel_toWithdraw_sort;

	private RelativeLayout rel_toWithdrawExtra_sort;

	private RelativeLayout rel_toTenderkoukuan_sort;

	private RelativeLayout rel_toGoumaizhaiquan_sort;

	private RelativeLayout rel_toHistory_sort;

	private RelativeLayout rel_toLiubiaojiedong_sort;

	private RelativeLayout rel_toJiekuanxiangguan_sort;
	private RelativeLayout rel_toFuwufei_sort;

	private FrameLayout frame_zhaiquanzhuanrang;

	private RelativeLayout rel_toZhaiquanzhuanrang_sort;

	private TextView tv_toZhaiquanzhuanrang_sort;

	private FrameLayout frame_fuwufei;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_deal_details);
		initView();
		setListener();
		setDefaultFragment(this, "", -1);
	}

	public void initView() {
		myticket = (RelativeLayout) this.findViewById(R.id.myticket);
		deal_top_img = (RelativeLayout) this.findViewById(R.id.deal_top_img);
		deal_top = (RelativeLayout) this.findViewById(R.id.deal_top);
		frame_all = (FrameLayout) findViewById(R.id.frame_all);
		frame_recharge = (FrameLayout) findViewById(R.id.frame_recharge);
		frame_lixihuankuan = (FrameLayout) findViewById(R.id.frame_lixihuankuan);
		frame_benjinhuankuan_sort = (FrameLayout) findViewById(R.id.frame_benjinhuankuan_sort);
		frame_Invitation_to_return = (FrameLayout) findViewById(R.id.frame_Invitation_to_return);
		frame_cunqianguan = (FrameLayout) findViewById(R.id.frame_cunqianguan);
		frame_coupon_return = (FrameLayout) findViewById(R.id.frame_coupon_return);
		frame_jianglixianjin = (FrameLayout) findViewById(R.id.frame_jianglixianjin);
		frame_zhaiquanzhuanrang = (FrameLayout) findViewById(R.id.frame_zhaiquanzhuanrang);// 债权转让
		frame_withdraw = (FrameLayout) findViewById(R.id.frame_withdraw);
		frame_withdrawExtra = (FrameLayout) findViewById(R.id.frame_withdrawExtra);
		frame_tenderkoukuan = (FrameLayout) findViewById(R.id.frame_tenderkoukuan);
		frame_goumaizhaiquan = (FrameLayout) findViewById(R.id.frame_goumaizhaiquan);// 购买债权
		frame_history = (FrameLayout) findViewById(R.id.frame_history);// 历史业务
		frame_liubiaojiedong = (FrameLayout) findViewById(R.id.frame_liubiaojiedong);
		frame_jiekuanxiangguan = (FrameLayout) findViewById(R.id.frame_jiekuanxiangguan);
		frame_fuwufei = (FrameLayout) findViewById(R.id.frame_fuwufei);// 服务费
		rel_selectSort = (RelativeLayout) findViewById(R.id.rel_selectSort);
		view_bottom = findViewById(R.id.view_bottom);
		deal_top_tv = (TextView) findViewById(R.id.deal_top_tv);// 标题栏
		initSelectSortView();
		initFragmentView();

	}

	/*
	 * 初始化选择交易明细分类页面的view
	 */
	private void initSelectSortView() {
		findViewById(R.id.rel_close_sort).setOnClickListener(this);// 关闭选择页面
		tv_toAll_sort = (TextView) findViewById(R.id.tv_toAll_sort);// 全部交易明细
		rel_toAll_sort = (RelativeLayout) findViewById(R.id.rel_toAll_sort);
		tv_toRecharge_sort = (TextView) findViewById(R.id.tv_toRecharge_sort);// 充值
		rel_toRecharge_sort = (RelativeLayout) findViewById(R.id.rel_toRecharge_sort);
		tv_toLixihuankuan_sort = (TextView) findViewById(R.id.tv_toLixihuankuan_sort);// 利息还款
		rel_toLixihuankuan_sort = (RelativeLayout) findViewById(R.id.rel_toLixihuankuan_sort);
		tv_toBenjinhuankuan_sort = (TextView) findViewById(R.id.tv_toBenjinhuankuan_sort);// 本金还款
		rel_toBenjinhuankuan_sort = (RelativeLayout) findViewById(R.id.rel_toBenjinhuankuan_sort);
		tv_toYaoqinghaoyou_sort = (TextView) findViewById(R.id.tv_toYaoqinghaoyou_sort);// 邀请好友返利
		rel_toYaoqinghaoyou_sort = (RelativeLayout) findViewById(R.id.rel_toYaoqinghaoyou_sort);
		tv_toCunqianguan_sort = (TextView) findViewById(R.id.tv_toCunqianguan_sort);// 存钱罐收益
		rel_toCunqianguan_sort = (RelativeLayout) findViewById(R.id.rel_toCunqianguan_sort);
		tv_toYouhuiquan_sort = (TextView) findViewById(R.id.tv_toYouhuiquan_sort);// 优惠券返现
		rel_toYouhuiquan_sort = (RelativeLayout) findViewById(R.id.rel_toYouhuiquan_sort);
		tv_toJianglixianjin_sort = (TextView) findViewById(R.id.tv_toJianglixianjin_sort);// 奖励现金
		rel_toJianglixianjin_sort = (RelativeLayout) findViewById(R.id.rel_toJianglixianjin_sort);
		rel_toZhaiquanzhuanrang_sort = (RelativeLayout) findViewById(R.id.rel_toZhaiquanzhuanrang_sort);// 债权转让
		tv_toZhaiquanzhuanrang_sort = (TextView) findViewById(R.id.tv_toZhaiquanzhuanrang_sort);
		tv_toWithdraw_sort = (TextView) findViewById(R.id.tv_toWithdraw_sort);// 提现
		rel_toWithdraw_sort = (RelativeLayout) findViewById(R.id.rel_toWithdraw_sort);
		tv_toWithdrawExtra_sort = (TextView) findViewById(R.id.tv_toWithdrawExtra_sort);// 提现手续费
		rel_toWithdrawExtra_sort = (RelativeLayout) findViewById(R.id.rel_toWithdrawExtra_sort);
		tv_toTenderkoukuan_sort = (TextView) findViewById(R.id.tv_toTenderkoukuan_sort);// 投资扣款
		rel_toTenderkoukuan_sort = (RelativeLayout) findViewById(R.id.rel_toTenderkoukuan_sort);
		tv_toGoumaizhaiquan_sort = (TextView) findViewById(R.id.tv_toGoumaizhaiquan_sort);// 购买债权
		rel_toGoumaizhaiquan_sort = (RelativeLayout) findViewById(R.id.rel_toGoumaizhaiquan_sort);
		tv_toHistory_sort = (TextView) findViewById(R.id.tv_toHistory_sort);// 历史业务
		rel_toHistory_sort = (RelativeLayout) findViewById(R.id.rel_toHistory_sort);
		tv_toLiubiaojiedong_sort = (TextView) findViewById(R.id.tv_toLiubiaojiedong_sort);// 流标解冻
		rel_toLiubiaojiedong_sort = (RelativeLayout) findViewById(R.id.rel_toLiubiaojiedong_sort);
		tv_toJiekuanxiangguan_sort = (TextView) findViewById(R.id.tv_toJiekuanxiangguan_sort);// 借款相关
		rel_toJiekuanxiangguan_sort = (RelativeLayout) findViewById(R.id.rel_toJiekuanxiangguan_sort);
		tv_toFuwufei_sort = (TextView) findViewById(R.id.tv_toFuwufei_sort);// 服务费
		rel_toFuwufei_sort = (RelativeLayout) findViewById(R.id.rel_toFuwufei_sort);
	}

	/*
	 * 初始化选择交易明细分类页面的view的点击监听
	 */
	private void setListenerForSelectSort() {
		rel_toAll_sort.setOnClickListener(this);
		rel_toRecharge_sort.setOnClickListener(this);
		rel_toLixihuankuan_sort.setOnClickListener(this);
		rel_toBenjinhuankuan_sort.setOnClickListener(this);
		rel_toYaoqinghaoyou_sort.setOnClickListener(this);
		rel_toCunqianguan_sort.setOnClickListener(this);
		rel_toYouhuiquan_sort.setOnClickListener(this);
		rel_toJianglixianjin_sort.setOnClickListener(this);
		rel_toZhaiquanzhuanrang_sort.setOnClickListener(this);
		rel_toWithdraw_sort.setOnClickListener(this);
		rel_toWithdrawExtra_sort.setOnClickListener(this);
		rel_toTenderkoukuan_sort.setOnClickListener(this);
		rel_toGoumaizhaiquan_sort.setOnClickListener(this);
		rel_toHistory_sort.setOnClickListener(this);
		rel_toLiubiaojiedong_sort.setOnClickListener(this);
		rel_toJiekuanxiangguan_sort.setOnClickListener(this);
		rel_toFuwufei_sort.setOnClickListener(this);
	}

	private void initFragmentView() {
		FragmentTransaction transaction = getSupportFragmentManager()
				.beginTransaction();
		transaction.replace(R.id.frame_all,
				DealDetailPinnerFragment.newInstance("", -1)); // 全部

		transaction.replace(R.id.frame_recharge,
				DealDetailFragment.newInstance("3004", -1)); // 充值

		transaction.replace(R.id.frame_lixihuankuan,
				DealDetailFragment.newInstance("3032", -1)); // 利息还款

		transaction.replace(R.id.frame_benjinhuankuan_sort,
				DealDetailFragment.newInstance("3036", -1)); // 本金还款

		transaction.replace(R.id.frame_Invitation_to_return,
				DealDetailFragment.newInstance("3018", -1)); // 邀请返现

		transaction.replace(R.id.frame_cunqianguan,
				DealDetailFragment.newInstance("3043", -1)); // 存钱罐收益

		transaction.replace(R.id.frame_coupon_return,
				DealDetailFragment.newInstance("3051", -1)); // 优惠券返现

		transaction.replace(R.id.frame_jianglixianjin,
				DealDetailFragment.newInstance("3041", -1)); // 奖励现金

		transaction.replace(R.id.frame_zhaiquanzhuanrang,
				DealDetailFragment.newInstance("3059", -1)); // 债权转让

		transaction.replace(R.id.frame_withdraw,
				DealDetailFragment.newInstance("3005", -1)); // 提现

		transaction.replace(R.id.frame_withdrawExtra,
				DealDetailFragment.newInstance("3010", -1)); // 提现手续费

		transaction.replace(R.id.frame_tenderkoukuan,
				DealDetailFragment.newInstance("3001", -1)); // 投资扣款

		transaction.replace(R.id.frame_goumaizhaiquan,
				DealDetailFragment.newInstance("3060", -1)); // 购买债权

		transaction.replace(R.id.frame_history,
				DealDetailFragment.newInstance("4007", -1)); // 历史业务

		transaction.replace(R.id.frame_liubiaojiedong,
				DealDetailFragment.newInstance("3011", -1)); // 流标解冻

		transaction.replace(R.id.frame_jiekuanxiangguan,
				DealDetailFragment.newInstance("4006", -1)); // 借款相关

		transaction.replace(R.id.frame_fuwufei,
				DealDetailFragment.newInstance("4008", -1)); // 服务费

		transaction.commit();
		// createWindow();
	}

	public void setListener() {
		myticket.setOnClickListener(this);
		deal_top_img.setOnClickListener(this);
		deal_top.setOnClickListener(this);
		view_bottom.setOnClickListener(this);
		setListenerForSelectSort();
	}

	@Override
	public void onClick(View v) {

		switch (v.getId()) {
		case R.id.deal_top_img:// 返回
			if (integerFlag % 2 != 0) {
				noshowWindow();
				integerFlag++;
			} else {
				finish();
			}
			break;
		case R.id.deal_top:
			SystemUtils.onEvent("Account_TradeDetails_Filter", 1);
			if (integerFlag % 2 != 0) {
				noshowWindow();
				integerFlag++;
			}
			break;
		case R.id.view_bottom:
			SystemUtils.onEvent("Account_TradeDetails_Filter", 1);
			if (integerFlag % 2 != 0) {
				noshowWindow();
				integerFlag++;
			}
			break;
		case R.id.myticket:
			SystemUtils.onEvent("Account_TradeDetails_Filter", 1);
			if (integerFlag % 2 == 0) {
				showWindow();
				// adapter.notifyDataSetChanged();
			} else {
				noshowWindow();
			}
			integerFlag++;
			break;

		case R.id.rel_close_sort:
			if (integerFlag % 2 != 0) {
				noshowWindow();
				integerFlag++;
			}
			break;

		case R.id.rel_toAll_sort: // 全部明细
			setDefaultFragment(DealDetailsActivity.this, "", -1);
			deal_top_tv.setText("交易明细");
			if (integerFlag % 2 != 0) {
				noshowWindow();
				integerFlag++;
			}
			break;

		case R.id.rel_toRecharge_sort: // 充值
			SystemUtils.onEvent("Account_TradeDetails_Recharge", 1);
			setDefaultFragment(DealDetailsActivity.this, "3004", -1);
			deal_top_tv.setText("充值明细");
			if (integerFlag % 2 != 0) {
				noshowWindow();
				integerFlag++;
			}
			break;

		case R.id.rel_toLixihuankuan_sort: // 利息还款
			setDefaultFragment(DealDetailsActivity.this, "3032", -1);
			deal_top_tv.setText("利息还款明细");
			if (integerFlag % 2 != 0) {
				noshowWindow();
				integerFlag++;
			}
			break;

		case R.id.rel_toBenjinhuankuan_sort: // 本金还款
			setDefaultFragment(DealDetailsActivity.this, "3036", -1);
			deal_top_tv.setText("本金还款明细");
			if (integerFlag % 2 != 0) {
				noshowWindow();
				integerFlag++;
			}
			break;

		case R.id.rel_toYaoqinghaoyou_sort: // 邀请好友返利
			SystemUtils.onEvent("Account_TradeDetails_InvitProfit", 1);
			setDefaultFragment(DealDetailsActivity.this, "3018", -1);
			deal_top_tv.setText("邀请好友返利明细");
			if (integerFlag % 2 != 0) {
				noshowWindow();
				integerFlag++;
			}
			break;

		case R.id.rel_toCunqianguan_sort: // 存钱罐收益
			setDefaultFragment(DealDetailsActivity.this, "3043", -1);
			deal_top_tv.setText("存钱罐收益明细");
			if (integerFlag % 2 != 0) {
				noshowWindow();
				integerFlag++;
			}
			break;

		case R.id.rel_toYouhuiquan_sort: // 优惠券返现
			SystemUtils.onEvent("Account_TradeDetails_CouponCrashBack", 1);
			setDefaultFragment(DealDetailsActivity.this, "3051", -1);
			deal_top_tv.setText("优惠券返现明细");
			if (integerFlag % 2 != 0) {
				noshowWindow();
				integerFlag++;
			}
			break;

		case R.id.rel_toJianglixianjin_sort: // 奖励现金
			setDefaultFragment(DealDetailsActivity.this, "3041", -1);
			deal_top_tv.setText("奖励现金明细");
			if (integerFlag % 2 != 0) {
				noshowWindow();
				integerFlag++;
			}
			break;

		case R.id.rel_toZhaiquanzhuanrang_sort: // 债权转让
			setDefaultFragment(DealDetailsActivity.this, "3059", -1);
			deal_top_tv.setText("债权转让明细");
			if (integerFlag % 2 != 0) {
				noshowWindow();
				integerFlag++;
			}
			break;

		case R.id.rel_toWithdraw_sort: // 提现
			setDefaultFragment(DealDetailsActivity.this, "3005", -1);
			deal_top_tv.setText("提现明细");
			if (integerFlag % 2 != 0) {
				noshowWindow();
				integerFlag++;
			}
			break;

		case R.id.rel_toWithdrawExtra_sort: // 提现手续费
			setDefaultFragment(DealDetailsActivity.this, "3010", -1);
			deal_top_tv.setText("提现手续费明细");
			if (integerFlag % 2 != 0) {
				noshowWindow();
				integerFlag++;
			}
			break;

		case R.id.rel_toTenderkoukuan_sort: // 投资扣款
			setDefaultFragment(DealDetailsActivity.this, "3001", -1);
			deal_top_tv.setText("投标扣款明细");
			if (integerFlag % 2 != 0) {
				noshowWindow();
				integerFlag++;
			}
			break;

		case R.id.rel_toGoumaizhaiquan_sort: // 购买债权
			setDefaultFragment(DealDetailsActivity.this, "3060", -1);
			deal_top_tv.setText("购买债权明细");
			if (integerFlag % 2 != 0) {
				noshowWindow();
				integerFlag++;
			}
			break;

		case R.id.rel_toHistory_sort: // 历史业务
			setDefaultFragment(DealDetailsActivity.this, "4007", -1);
			deal_top_tv.setText("历史业务明细");
			if (integerFlag % 2 != 0) {
				noshowWindow();
				integerFlag++;
			}
			break;

		case R.id.rel_toLiubiaojiedong_sort: // 流标解冻
			setDefaultFragment(DealDetailsActivity.this, "3011", -1);
			deal_top_tv.setText("流标解冻明细");
			if (integerFlag % 2 != 0) {
				noshowWindow();
				integerFlag++;
			}
			break;

		case R.id.rel_toJiekuanxiangguan_sort: // 借款相关
			setDefaultFragment(DealDetailsActivity.this, "4006", -1);
			deal_top_tv.setText("借款相关明细");
			if (integerFlag % 2 != 0) {
				noshowWindow();
				integerFlag++;
			}
			break;

		case R.id.rel_toFuwufei_sort: // 服务费
			setDefaultFragment(DealDetailsActivity.this, "4008", -1);
			deal_top_tv.setText("服务费明细");
			if (integerFlag % 2 != 0) {
				noshowWindow();
				integerFlag++;
			}
			break;

		}
	}

	public void showWindow() {
		showAnimTranslate(rel_selectSort);
		showAnimTranslateup(view_bottom);
	}

	public void noshowWindow() {
		noshowAnimTranslate(rel_selectSort);
		noshowAnimTranslateup(view_bottom);
	}

	public void createWindow() {
		list = new ArrayList<String>();
		list.add("全部");
		list.add("定期");
		list.add("天天赚");
		list.add("充值");
		list.add("提现");
		list.add("优惠券返现");
		list.add("利息");
		list.add("邀请收益");
		list.add("其他");
		// adapter = new GridViewAdapater(this, classify_tv);
		// adapter.appendData(list, true);
		// gridview.setSelector(new ColorDrawable(Color.TRANSPARENT));
		// gridview.setAdapter(adapter);
		// adapter.setonGridViewItemCliclistener(new
		// OnGridViewItemCliclistener() {
		//
		// @Override
		// public void onPosition(int position) {
		// switch (position) {
		// case 0:
		//
		// setDefaultFragment(DealDetailsActivity.this, "", -1);
		// // classify_tv.setText("投标");
		// // LogUtil.e("position", "0");
		// if (integerFlag % 2 != 0) {
		// noshowWindow();
		// integerFlag++;
		// }
		// break;
		// case 1:
		// SystemUtils.onEvent("Account_TradeDetails_Regular", 1);
		// setDefaultFragment(DealDetailsActivity.this, "4001", -1);
		// // classify_tv.setText("放款");
		// // LogUtil.e("position", "1");
		// if (integerFlag % 2 != 0) {
		// noshowWindow();
		// integerFlag++;
		// }
		// break;
		// case 2:
		// SystemUtils.onEvent("Account_TradeDetails_Current", 1);
		// setDefaultFragment(DealDetailsActivity.this, "4002", -1);
		// // LogUtil.e("position", "2");
		// // classify_tv.setText("充值");
		// if (integerFlag % 2 != 0) {
		// noshowWindow();
		// integerFlag++;
		// }
		// break;
		// case 3:
		// SystemUtils.onEvent("Account_TradeDetails_Recharge", 1);
		// setDefaultFragment(DealDetailsActivity.this, "3004", -1);
		// // LogUtil.e("position", "3");
		// // classify_tv.setText("提现");
		// if (integerFlag % 2 != 0) {
		// noshowWindow();
		// integerFlag++;
		// }
		// break;
		// case 4:
		// SystemUtils.onEvent("Account_TradeDetails_WithDraw", 1);
		// setDefaultFragment(DealDetailsActivity.this, "3005", -1);
		// // LogUtil.e("position", "4");
		// // classify_tv.setText("解冻");
		// if (integerFlag % 2 != 0) {
		// noshowWindow();
		// integerFlag++;
		// }
		// break;
		// case 5:
		// SystemUtils.onEvent("Account_TradeDetails_CouponCrashBack",
		// 1);
		// setDefaultFragment(DealDetailsActivity.this, "4003", -1);
		// // classify_tv.setText("服务费");
		// // LogUtil.e("position", "5");
		// if (integerFlag % 2 != 0) {
		// noshowWindow();
		// integerFlag++;
		// }
		// break;
		// case 6:
		// SystemUtils.onEvent("Account_TradeDetails_Profit", 1);
		// setDefaultFragment(DealDetailsActivity.this, "4004", -1);
		// // LogUtil.e("position", "6");
		// // classify_tv.setText("利息");
		// if (integerFlag % 2 != 0) {
		// noshowWindow();
		// integerFlag++;
		// }
		// break;
		// case 7:
		// SystemUtils.onEvent("Account_TradeDetails_InvitProfit", 1);
		// setDefaultFragment(DealDetailsActivity.this, "3018", -1);
		// // LogUtil.e("position", "7");
		// // classify_tv.setText("管理费");
		// if (integerFlag % 2 != 0) {
		// noshowWindow();
		// integerFlag++;
		// }
		// break;
		// case 8:
		// SystemUtils.onEvent("Account_TradeDetails_Others", 1);
		// setDefaultFragment(DealDetailsActivity.this, "4005", -1);
		// // LogUtil.e("position", "8");
		// // classify_tv.setText("红包返现");
		// if (integerFlag % 2 != 0) {
		// noshowWindow();
		// integerFlag++;
		// }
		// break;
		// }
		// }
		// });
	}

	/**
     * 
     */

	public void setDefaultFragment(DealDetailsActivity dealDetailsActivity,
			String tradeType, int status) {
		setTextcolorAndBackground(tradeType);
		if ("".equals(tradeType) && status == -1) { // 全部
			frame_all.setVisibility(View.VISIBLE);
		} else {
			frame_all.setVisibility(View.GONE);
		}

		if ("3004".equals(tradeType) && status == -1) { // 充值
			frame_recharge.setVisibility(View.VISIBLE);
		} else {
			frame_recharge.setVisibility(View.GONE);
		}

		if ("3032".equals(tradeType) && status == -1) { // 利息还款
			frame_lixihuankuan.setVisibility(View.VISIBLE);
		} else {
			frame_lixihuankuan.setVisibility(View.GONE);
		}

		if ("3036".equals(tradeType) && status == -1) { // 本金还款
			frame_benjinhuankuan_sort.setVisibility(View.VISIBLE);
		} else {
			frame_benjinhuankuan_sort.setVisibility(View.GONE);
		}

		if ("3018".equals(tradeType) && status == -1) { // 邀请返现
			frame_Invitation_to_return.setVisibility(View.VISIBLE);
		} else {
			frame_Invitation_to_return.setVisibility(View.GONE);
		}

		if ("3043".equals(tradeType) && status == -1) { // 存钱罐收益
			frame_cunqianguan.setVisibility(View.VISIBLE);
		} else {
			frame_cunqianguan.setVisibility(View.GONE);
		}

		if ("3051".equals(tradeType) && status == -1) { // 优惠券返现
			frame_coupon_return.setVisibility(View.VISIBLE);
		} else {
			frame_coupon_return.setVisibility(View.GONE);
		}

		if ("3041".equals(tradeType) && status == -1) { // 奖励现金
			frame_jianglixianjin.setVisibility(View.VISIBLE);
		} else {
			frame_jianglixianjin.setVisibility(View.GONE);
		}

		if ("3059".equals(tradeType) && status == -1) { // 债权转让
			frame_zhaiquanzhuanrang.setVisibility(View.VISIBLE);
		} else {
			frame_zhaiquanzhuanrang.setVisibility(View.GONE);
		}

		if ("3005".equals(tradeType) && status == -1) { // 提现
			frame_withdraw.setVisibility(View.VISIBLE);
		} else {
			frame_withdraw.setVisibility(View.GONE);
		}

		if ("3010".equals(tradeType) && status == -1) { // 提现手续费
			frame_withdrawExtra.setVisibility(View.VISIBLE);
		} else {
			frame_withdrawExtra.setVisibility(View.GONE);
		}

		if ("3001".equals(tradeType) && status == -1) { // 投资扣款
			frame_tenderkoukuan.setVisibility(View.VISIBLE);
		} else {
			frame_tenderkoukuan.setVisibility(View.GONE);
		}

		if ("3060".equals(tradeType) && status == -1) { // 购买债权
			frame_goumaizhaiquan.setVisibility(View.VISIBLE);
		} else {
			frame_goumaizhaiquan.setVisibility(View.GONE);
		}

		if ("4007".equals(tradeType) && status == -1) { // 历史业务
			frame_history.setVisibility(View.VISIBLE);
		} else {
			frame_history.setVisibility(View.GONE);
		}

		if ("3011".equals(tradeType) && status == -1) { // 流标解冻
			frame_liubiaojiedong.setVisibility(View.VISIBLE);
		} else {
			frame_liubiaojiedong.setVisibility(View.GONE);
		}

		if ("4006".equals(tradeType) && status == -1) { // 借款相关
			frame_jiekuanxiangguan.setVisibility(View.VISIBLE);
		} else {
			frame_jiekuanxiangguan.setVisibility(View.GONE);
		}

		if ("4008".equals(tradeType) && status == -1) { // 服务费
			frame_fuwufei.setVisibility(View.VISIBLE);
		} else {
			frame_fuwufei.setVisibility(View.GONE);
		}

	}

	public void showAnimTranslate(final View view) {
		ObjectAnimator animation;
		PropertyValuesHolder pvhY = PropertyValuesHolder.ofFloat(
				"translationY", -1000, 0);
		animation = ObjectAnimator.ofPropertyValuesHolder(view, pvhY);
		animation.setDuration(300);
		animation.addListener(new AnimatorListener() {

			@Override
			public void onAnimationStart(Animator animation) {
				view.setVisibility(View.VISIBLE);

			}

			@Override
			public void onAnimationRepeat(Animator animation) {
				// TODO Auto-generated method stub

			}

			@Override
			public void onAnimationEnd(Animator animation) {
			}

			@Override
			public void onAnimationCancel(Animator animation) {
				// TODO Auto-generated method stub

			}
		});
		animation.start();
	}

	public void noshowAnimTranslate(final View view) {
		ObjectAnimator animation;
		PropertyValuesHolder pvhY = PropertyValuesHolder.ofFloat(
				"translationY", 0, -1000);
		animation = ObjectAnimator.ofPropertyValuesHolder(view, pvhY);
		animation.setDuration(300);
		animation.addListener(new AnimatorListener() {

			@Override
			public void onAnimationStart(Animator animation) {
				// TODO Auto-generated method stub

			}

			@Override
			public void onAnimationRepeat(Animator animation) {
				// TODO Auto-generated method stub

			}

			@Override
			public void onAnimationEnd(Animator animation) {
				view.setVisibility(View.GONE);
			}

			@Override
			public void onAnimationCancel(Animator animation) {
				// TODO Auto-generated method stub

			}
		});
		animation.start();
	}

	public void showAnimTranslateup(final View view) {
		ObjectAnimator animation;
		PropertyValuesHolder pvhY = PropertyValuesHolder.ofFloat(
				"translationY", 10000, 0);
		animation = ObjectAnimator.ofPropertyValuesHolder(view, pvhY);
		animation.setDuration(300);
		animation.addListener(new AnimatorListener() {

			@Override
			public void onAnimationStart(Animator animation) {
				view.setVisibility(View.VISIBLE);

			}

			@Override
			public void onAnimationRepeat(Animator animation) {
				// TODO Auto-generated method stub

			}

			@Override
			public void onAnimationEnd(Animator animation) {
			}

			@Override
			public void onAnimationCancel(Animator animation) {
				// TODO Auto-generated method stub

			}
		});
		animation.start();
	}

	public void noshowAnimTranslateup(final View view) {
		ObjectAnimator animation;
		PropertyValuesHolder pvhY = PropertyValuesHolder.ofFloat(
				"translationY", 0, 10000);
		animation = ObjectAnimator.ofPropertyValuesHolder(view, pvhY);
		animation.setDuration(300);
		animation.addListener(new AnimatorListener() {

			@Override
			public void onAnimationStart(Animator animation) {

			}

			@Override
			public void onAnimationRepeat(Animator animation) {

			}

			@Override
			public void onAnimationEnd(Animator animation) {
				view.setVisibility(View.GONE);
			}

			@Override
			public void onAnimationCancel(Animator animation) {
				// TODO Auto-generated method stub

			}
		});
		animation.start();
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK) {
			if (integerFlag % 2 != 0) {
				noshowWindow();
				integerFlag++;
			} else {
				finish();
			}
			return true;
		}
		return super.onKeyDown(keyCode, event);
	}

	private void setTextcolorAndBackground(String type) {
		if ("".equals(type)) {
			tv_toAll_sort.setTextColor(Color.parseColor("#ffffff"));
			tv_toAll_sort
					.setBackgroundResource(R.drawable.selectall_exchange_shape);
		} else {
			tv_toAll_sort.setTextColor(Color.parseColor("#a9a9a9"));
			tv_toAll_sort.setBackgroundColor(Color.parseColor("#ffffff"));
		}

		if ("3004".equals(type)) {
			tv_toRecharge_sort.setTextColor(Color.parseColor("#ffffff"));
			tv_toRecharge_sort
					.setBackgroundResource(R.drawable.selectall_exchange_shape);
		} else {
			tv_toRecharge_sort.setTextColor(Color.parseColor("#a9a9a9"));
			tv_toRecharge_sort.setBackgroundColor(Color.parseColor("#ffffff"));
		}

		if ("3032".equals(type)) {
			tv_toLixihuankuan_sort.setTextColor(Color.parseColor("#ffffff"));
			tv_toLixihuankuan_sort
					.setBackgroundResource(R.drawable.selectall_exchange_shape);
		} else {
			tv_toLixihuankuan_sort.setTextColor(Color.parseColor("#a9a9a9"));
			tv_toLixihuankuan_sort.setBackgroundColor(Color
					.parseColor("#ffffff"));
		}

		if ("3036".equals(type)) {
			tv_toBenjinhuankuan_sort.setTextColor(Color.parseColor("#ffffff"));
			tv_toBenjinhuankuan_sort
					.setBackgroundResource(R.drawable.selectall_exchange_shape);
		} else {
			tv_toBenjinhuankuan_sort.setTextColor(Color.parseColor("#a9a9a9"));
			tv_toBenjinhuankuan_sort.setBackgroundColor(Color
					.parseColor("#ffffff"));
		}

		if ("3018".equals(type)) {
			tv_toYaoqinghaoyou_sort.setTextColor(Color.parseColor("#ffffff"));
			tv_toYaoqinghaoyou_sort
					.setBackgroundResource(R.drawable.selectall_exchange_shape);
		} else {
			tv_toYaoqinghaoyou_sort.setTextColor(Color.parseColor("#a9a9a9"));
			tv_toYaoqinghaoyou_sort.setBackgroundColor(Color
					.parseColor("#ffffff"));
		}

		if ("3043".equals(type)) {
			tv_toCunqianguan_sort.setTextColor(Color.parseColor("#ffffff"));
			tv_toCunqianguan_sort
					.setBackgroundResource(R.drawable.selectall_exchange_shape);
		} else {
			tv_toCunqianguan_sort.setTextColor(Color.parseColor("#a9a9a9"));
			tv_toCunqianguan_sort.setBackgroundColor(Color
					.parseColor("#ffffff"));
		}

		if ("3051".equals(type)) {
			tv_toYouhuiquan_sort.setTextColor(Color.parseColor("#ffffff"));
			tv_toYouhuiquan_sort
					.setBackgroundResource(R.drawable.selectall_exchange_shape);
		} else {
			tv_toYouhuiquan_sort.setTextColor(Color.parseColor("#a9a9a9"));
			tv_toYouhuiquan_sort
					.setBackgroundColor(Color.parseColor("#ffffff"));
		}

		if ("3041".equals(type)) {
			tv_toJianglixianjin_sort.setTextColor(Color.parseColor("#ffffff"));
			tv_toJianglixianjin_sort
					.setBackgroundResource(R.drawable.selectall_exchange_shape);
		} else {
			tv_toJianglixianjin_sort.setTextColor(Color.parseColor("#a9a9a9"));
			tv_toJianglixianjin_sort.setBackgroundColor(Color
					.parseColor("#ffffff"));
		}

		if ("3059".equals(type)) {
			tv_toZhaiquanzhuanrang_sort.setTextColor(Color
					.parseColor("#ffffff"));
			tv_toZhaiquanzhuanrang_sort
					.setBackgroundResource(R.drawable.selectall_exchange_shape);
		} else {
			tv_toZhaiquanzhuanrang_sort.setTextColor(Color
					.parseColor("#a9a9a9"));
			tv_toZhaiquanzhuanrang_sort.setBackgroundColor(Color
					.parseColor("#ffffff"));
		}

		if ("3005".equals(type)) {
			tv_toWithdraw_sort.setTextColor(Color.parseColor("#ffffff"));
			tv_toWithdraw_sort
					.setBackgroundResource(R.drawable.selectall_exchange_shape);
		} else {
			tv_toWithdraw_sort.setTextColor(Color.parseColor("#a9a9a9"));
			tv_toWithdraw_sort.setBackgroundColor(Color.parseColor("#ffffff"));
		}

		if ("3010".equals(type)) {
			tv_toWithdrawExtra_sort.setTextColor(Color.parseColor("#ffffff"));
			tv_toWithdrawExtra_sort
					.setBackgroundResource(R.drawable.selectall_exchange_shape);
		} else {
			tv_toWithdrawExtra_sort.setTextColor(Color.parseColor("#a9a9a9"));
			tv_toWithdrawExtra_sort.setBackgroundColor(Color
					.parseColor("#ffffff"));
		}

		if ("3001".equals(type)) {
			tv_toTenderkoukuan_sort.setTextColor(Color.parseColor("#ffffff"));
			tv_toTenderkoukuan_sort
					.setBackgroundResource(R.drawable.selectall_exchange_shape);
		} else {
			tv_toTenderkoukuan_sort.setTextColor(Color.parseColor("#a9a9a9"));
			tv_toTenderkoukuan_sort.setBackgroundColor(Color
					.parseColor("#ffffff"));
		}

		if ("3060".equals(type)) {
			tv_toGoumaizhaiquan_sort.setTextColor(Color.parseColor("#ffffff"));
			tv_toGoumaizhaiquan_sort
					.setBackgroundResource(R.drawable.selectall_exchange_shape);
		} else {
			tv_toGoumaizhaiquan_sort.setTextColor(Color.parseColor("#a9a9a9"));
			tv_toGoumaizhaiquan_sort.setBackgroundColor(Color
					.parseColor("#ffffff"));
		}

		if ("4007".equals(type)) {
			tv_toHistory_sort.setTextColor(Color.parseColor("#ffffff"));
			tv_toHistory_sort
					.setBackgroundResource(R.drawable.selectall_exchange_shape);
		} else {
			tv_toHistory_sort.setTextColor(Color.parseColor("#a9a9a9"));
			tv_toHistory_sort.setBackgroundColor(Color.parseColor("#ffffff"));
		}

		if ("3011".equals(type)) {
			tv_toLiubiaojiedong_sort.setTextColor(Color.parseColor("#ffffff"));
			tv_toLiubiaojiedong_sort
					.setBackgroundResource(R.drawable.selectall_exchange_shape);
		} else {
			tv_toLiubiaojiedong_sort.setTextColor(Color.parseColor("#a9a9a9"));
			tv_toLiubiaojiedong_sort.setBackgroundColor(Color
					.parseColor("#ffffff"));
		}

		if ("4006".equals(type)) {
			tv_toJiekuanxiangguan_sort
					.setTextColor(Color.parseColor("#ffffff"));
			tv_toJiekuanxiangguan_sort
					.setBackgroundResource(R.drawable.selectall_exchange_shape);
		} else {
			tv_toJiekuanxiangguan_sort
					.setTextColor(Color.parseColor("#a9a9a9"));
			tv_toJiekuanxiangguan_sort.setBackgroundColor(Color
					.parseColor("#ffffff"));
		}

		if ("4008".equals(type)) {
			tv_toFuwufei_sort.setTextColor(Color.parseColor("#ffffff"));
			tv_toFuwufei_sort
					.setBackgroundResource(R.drawable.selectall_exchange_shape);
		} else {
			tv_toFuwufei_sort.setTextColor(Color.parseColor("#a9a9a9"));
			tv_toFuwufei_sort.setBackgroundColor(Color.parseColor("#ffffff"));
		}
	}
}
